package com.hejia.bulbul.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hejia.alauda.entity.Popularize;
import com.hejia.alauda.entity.PopularizeVisit;
import com.hejia.alauda.service.PopularizeService;
import com.hejia.alauda.utils.Pager;
import com.hejia.alauda.utils.PagerHelper;
import com.hejia.bulbul.service.PopularizeVisitService;

@Controller
@RequestMapping("popularizevisits")
public class PopularizeVisitController {

	@Resource
	private PopularizeVisitService popularizeVisitService;
	
	@Resource
	private PopularizeService popularizeService;
	
	@RequestMapping
	public String list(Long popularizeId, Pager<PopularizeVisit> pager, ModelMap model){

		Popularize popularize = popularizeService.findById(popularizeId.longValue());
		pager = popularizeVisitService.findPopularizeVisitByPopularizeId(popularizeId, pager);
		
		PagerHelper<PopularizeVisit> helper = new PagerHelper<>();
        helper.setPager(pager);
        Map<String, String> map = new HashMap<>();
        if (popularizeId != null) {
            map.put("popularizeId", popularizeId.toString());
        }
        helper.setParams(map);
        helper.setBaseUrl("/popularizevisits");
        
        model.put("pagerHelper", helper);
        model.put("popularize", popularize);
		model.put("popularizeVisits", pager);
		
		return "popularizevisit/list";
	}
}
